
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;

import java.io.IOException;
import java.io.InputStream;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws IOException {
//       接口地址： http://www.kuaidi100.com/query?type=yuantong&postid=11111111111
        DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
        HttpHost host = new HttpHost("www.kuaidi100.com");
        HttpGet request = new HttpGet("/query?type=yuantong&postid=11111111111");
        HttpResponse httpResponse = defaultHttpClient.execute(host, request);
        //这里是流操作了
        InputStream is = httpResponse.getEntity().getContent();

        //把流转字符串
        byte[] bytes = new byte[1024];
        int size = 0;
        while ((size = is.read(bytes)) > 0) {
            String s = new String(bytes, 0, size);
            System.out.println(s);
        }
        is.close();
        demo1();

    }

    public static void demo1() throws IOException {
        System.out.println("===============demo1===============");
        //接口地址： http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=18570651508
        DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
        HttpHost host = new HttpHost("tcc.taobao.com");
        HttpGet request = new HttpGet("/cc/json/mobile_tel_segment.htm");
        BasicHttpParams params = new BasicHttpParams();
        params.setParameter("tel", "18570651508");
        request.setParams(params);
        HttpResponse httpResponse = defaultHttpClient.execute(host, request);
        //这里是流操作了
        InputStream is = httpResponse.getEntity().getContent();

        //把流转字符串
        byte[] bytes = new byte[1024];
        int size = 0;
        while ((size = is.read(bytes)) > 0) {
            String s = new String(bytes, 0, size);
            System.out.println(s);
        }
        is.close();
    }
}
